package com.example.nearby;

import java.util.ArrayList;
import java.util.List;

public class SessionManager
{
	private String username;
	private List<String[]> messages;
	private static SessionManager session;
	
	private SessionManager(String user) {
		username = user;
		messages = new <String[]>ArrayList();
	}
	
	public static SessionManager getSession() {
		return SessionManager.session;
	}
	
	public static void setSession(String user) {
		SessionManager.session = new SessionManager(user);
	}
	
	public void addMsg(String key, String value) {
		messages.add(new String[]{key.toLowerCase(), value});
	}
	
	public String getMessage(String key) {
		for(int i=0; i<messages.size(); i++) {
			String[] msg = messages.get(i);
			if(msg[0].equals(key.toLowerCase())) {
				return msg[1];
			}
		}
		return "";
	}
	
	public String getUsername() {
		return username;
	}
	public void debug() {
		System.out.println("Session[]:");
		for(int i=0; i<messages.size(); i++) {
			String[] msg = messages.get(i);
			System.out.println("   " + msg[0] + " => " + msg[1]);
		}
	}
}